<template>
	<view>
		<swiper 
			circular
			class="douyin-video" 
			vertical easing-function="easeOutCubic" 
			:style="{height: pageHeight}"
			@change="changeVideo"
		>
			
			<swiper-item class="video-item" v-for="(item, index) in list" :key="index">
				<view class="video">

					<video
						v-if="item.isFull == true"
						:style="{height: pageHeight}"
						:src="item.video_url" 
						:controls="false" 
						:autoplay="false" 
						loop
						:show-loading="true" 
						object-fit="fill" 
						:enable-play-gesture="false" 
						:show-play-btn="false"
						:show-fullscreen-btn="false"
						:id="'video'+index"
						@click="clickVideo"
					></video>
					
					<video
						v-else
						:style="{height: pageHeight}"
						:src="item.video_url" 
						:controls="false" 
						:autoplay="false" 
						loop
						:show-loading="true" 
						object-fit="contain" 
						:enable-play-gesture="false" 
						:show-play-btn="false"
						:show-fullscreen-btn="false"
						:id="'video'+index"
						@click="clickVideo"
					></video>
					
				</view>
				
				<!-- 播放按钮 -->
				<view class="isplay" :class="{isblock: isblobk}" @click="clickVideo">
					<image src="../../static/icon/isplay.png" mode="widthFix"></image>
				</view>
				
				<!-- 视频信息 -->
				<view class="userinfo">
					<view class="nickname">@MK鹦鹉</view>
					<!-- 视频介绍 -->
					<view class="video-describe">600块的毛蛋什么味道?这么大的眼睛,真的可惜了600快的毛蛋什么味道?这么大的眼睛,真的可惜了
					</view>
					<!-- 音乐信息 -->
					<view class="userMusic">
						<text class="iconfont icon-douyin"></text>
						@MK鹦鹉的原创音乐
						<text class="more">展开</text>
					</view>
				</view>
				<!-- 交互按钮 -->
				<view class="jiaohu">
					<view class="userHeaderImg icon">
						<image src="../../static/icon/6.jpg" mode="widthFix"></image>
						<text class="add">+</text>
					</view>
					<view class="shouchang icon">
						<image src="../../static/icon/shoucang.png" mode="widthFix"></image>
						<text>249</text>
					</view>
					<view class="shouchang icon">
						<image src="../../static/icon/pinglun.png" mode="widthFix"></image>
						<text>24</text>
					</view>
					<view class="shouchang icon">
						<image src="../../static/icon/zhuanfa.png" mode="widthFix"></image>
						<text>79</text>
					</view>
					<view class="chagnpian icon">
						<image src="../../static/icon/6.jpg" mode="widthFix"></image>
					</view>
				</view>
			</swiper-item>



		</swiper>
	</view>
</template>

<script>
	var flag = 1;
	export default {
		name: "douyin-video",
		data() {
			return {
				pageHeight: "",
				videoId: 0,
				isblobk: false
			};
		},
		props:{
			list: {
				type: Array,
				default() {
					return [];
				}
			}
		},
		created() {
			
		},
		methods: {
			// 点击视频播放暂停事件
			clickVideo() {
				if (flag == 1) {
					console.log("暂停视频");
					this.isblobk = true
					for (let i = 0; i < this.list.length; i++) {
						let temp = "video"+i;
						uni.createVideoContext(temp, this).pause();
					}
					flag = 0;
				} else {
					console.log("播放视频");
					this.isblobk = false
					this.playVideo();
					flag = 1;
				}
			},
			
			// current 改变时触发
			changeVideo(e) {
				console.log(e.detail.current);
				this.isblobk = false
				flag = 1;
				this.videoId = e.detail.current;
				this.playVideo()
			},
			

			playVideo() {
				let videoId = "video"+this.videoId
				uni.createVideoContext(videoId, this).play()
				for (let i = 0; i < this.list.length; i++) {
					let temp = "video"+i;
					if (temp != videoId) {
						uni.createVideoContext(temp, this).pause();
					}
				}
			}
		},
		mounted() {
			this.playVideo()
			this.pageHeight = "calc(100vh - "+getApp().globalData.statusBar+ "px" + ")"
		}
	}
</script>

<style scoped lang="scss">
	.douyin-video {
		width: 100vw;
		height: calc(100vh - 37px);
		background-color: #000000;

		.video-item {
			position: relative;

			.video {
				position: absolute;
				bottom: 0;
				left: 0;

				video {
					width: 100vw;
					height: calc(100vh - 37px);
					background-color: #000000;
				}
			}
			
			.isplay {
				display: none;
				position: absolute;
				width: 160rpx;
				height: 160rpx;
				left: 50%;
				top: 50%;
				transform: translate(-50%, -50%);
				image {
					width: 100%;
					height: 100%;
					opacity: 0.5;
				}
			}
			
			.isblock {
				display: block;
			}

			.userinfo {
				position: absolute;
				bottom: 20rpx;
				left: 20rpx;
				width: 450rpx;
				color: #fff;

				// background-color: #000;
				.nickname {
					color: #fff;
					font-weight: 800;
					margin-bottom: 20rpx;
				}

				.video-describe {
					color: #dadada;
					font-size: 29rpx;
					line-height: 46rpx;
					height: 90rpx;
					/* 多行文本溢出隐藏 */
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					/*设置对齐模式*/
					-webkit-line-clamp: 2;
					/*设置多行的行数*/

				}

				.userMusic {
					position: relative;
					color: #dadada;
					font-size: 29rpx;
					margin-top: 30rpx;

					.iconfont {
						font-size: 26rpx;
						margin-right: 15rpx;
						color: #dadada;
					}

					.more {
						position: absolute;
						right: -68rpx;
						bottom: 72rpx;
						font-size: 26rpx;
						background-color: rgba(0, 0, 0, .4);
						color: #fff;
						padding: 5rpx 10rpx;
						box-sizing: border-box;
						border-radius: 6rpx;
					}
				}
			}

			.jiaohu {
				position: absolute;
				right: 15rpx;
				bottom: 24rpx;
				width: 110rpx;

				image {
					width: 78rpx;
					height: 78rpx;
				}

				.icon {
					display: flex;
					flex-direction: column;
					align-items: center;
					margin-bottom: 50rpx;
					color: #fff;
				}

				.userHeaderImg {
					image {
						width: 110rpx;
						height: 110rpx;
						border-radius: 50%;
						border: 2px solid #fff;
						box-sizing: border-box;
					}

					.add {
						width: 40rpx;
						height: 40rpx;
						border-radius: 50%;
						line-height: 40rpx;
						text-align: center;
						color: #fff;
						font-weight: 800;
						margin-top: -26rpx;
						background-color: red;
					}
				}

				.chagnpian {
					margin: 0;
					width: 100rpx;
					height: 100rpx;
					box-sizing: border-box;
					border-radius: 50%;
					border: 20rpx solid #303030;

					image {
						width: 100%;
						height: 100%;
						border-radius: 50%;
					}
				}
			}
		}

	}
</style>
